require "ImguiWin/BaseImguiWindow"
require "Common/GUIFun"


local P = NewClass(BaseImguiWindow, ClassFromFile(...));




local GUILayout = UnityEngine.GUILayout
local GUI = UnityEngine.GUI
local Screen = UnityEngine.Screen
local dontDestroyObjs = nil

local addSpace = 50


local cmdText = ""

local guildIDText = ""
local areaText = ""
local goldText = ""
local diamondText = ""
local entityId = ""
local luaStr = ""

local winNames = 
{
	"LangSettingWindow", 
	"EffectSettingWindow",
	"QuickTeleportWindow",
	"AddEntityWindow",
	"AddItemWindow",
	"AddChipWindow",
	"StartTutorialWindow",
	"StartWeekActivityWindow",
	"ChangeRankTypeWindow",
	"SkillEditWindow",
	"ExecuteLuaWindow",
	"SystemInfoWindow", 
	"ScreenInfoWindow", 
	"VoiceManagerInfoWindow", 
	"LightInfoWindow", 
	"ParticleInfoWindow", 
	"AssetBundleInfoWindow", 
}

local playerpref_prefix = "command_"

function P:Init(params)

end


function P:Cmd(msg, donClose)
	KBEngineLua.player():sendChatMessage(msg)
	if not donClose then
		self._funObj:Close()
	end
end




function P:Show()
	-- local panel = self._dataObj:GetComponent(typeof(UIPanel))
	-- local worldCorners = panel.worldCorners
	-- local lb = worldCorners[0]
	-- local rt = worldCorners[2]
	-- local camera = panel.anchorCamera
	-- lb = camera:WorldToScreenPoint(lb)
	-- rt = camera:WorldToScreenPoint(rt)

	-- local space = 0
	-- GUILayout.BeginArea(UnityEngine.Rect.New(lb.x, lb.y, rt.x - lb.x, rt.y - lb.y))

	GUILayout.BeginArea(self:GetFullScreenAreaRect())
	GUILayout.BeginVertical()



	self.guiInfo.scrollPos = GUILayout.BeginScrollView(self.guiInfo.scrollPos, false, true, GUILayout.Width(Screen.width));
	GUILayout.BeginVertical()




	-- lang begin
	-- GUILayout.BeginHorizontal()
	-- GUILayout.BeginVertical()

	-- for k,v in ipairs(winNames) do
	-- 	local winName = v
	-- 	GUIFun.Label("", true, space)
	-- 	if GUIFun.Button(winName, true, 0) then
	-- 		require("ImguiWin/"..winName.."")
	-- 		RootWindowManager.instance:ShowWindow("ImguiWindow"):Init({class = _G[winName]});
	-- 	end
	-- end

	-- GUILayout.EndVertical()

	
	-- GUILayout.FlexibleSpace()
	-- GUILayout.EndHorizontal()
	-- lang end




	GUIFun.Label("", true, space)
	GUIFun.Label("", true, space)




	-- free camera begin
	-- GUILayout.BeginHorizontal()
	
	-- if GUIFun.Button("free camera", false, 0) then
	-- 	KBEngineLua.player().gameEntity.cameraFollow:FreeCamera()
	-- end
	-- GUILayout.FlexibleSpace()
	-- GUILayout.EndHorizontal()
	-- free camera end












	-- 设置开关 begin
	GUILayout.BeginVertical()
	GUIFun.Label("setting: ", false, space)



	if GUIFun.Button("gui log switch", true, 0) then
		SwitchConfig.isEnableGuiLog = not SwitchConfig.isEnableGuiLog
		--SettingEx.bool.isEnableGuiLog = SwitchConfig.isEnableGuiLog
		Login.UpdateGuiLog()
		self._funObj:Close()
	end

	GUIFun.Label("", false, space)

	if GUIFun.Button("show dont destroy objects in hdg", true, 0) then
		Login.ShowDontDestroyObjectsInHdg()
	end

	-- ObjectTranslator begin
	GUILayout.BeginHorizontal()
	if GUIFun.Button("gc", false, 0) then
		collectgarbage("collect")
	end
	GUILayout.FlexibleSpace()
	GUILayout.EndHorizontal()
	-- ObjectTranslator end

	GUIFun.Label("", false, space)
	GUIFun.Label("", false, space)

	-- GUILayout.BeginHorizontal()
	-- if GUIFun.Button("print navigation info", false, 0) then
	-- 	if NavigationController and NavigationController.startPos then
	-- 		logError("navigation info: start( "..tostring(NavigationController.startMapId).." , "..tostring(NavigationController.startPos).." )    end( "..tostring(NavigationController.endMapId).." , "..Vector3.__tostring(NavigationController.endPos).." )")
	-- 	else
	-- 		logError("map target info: start( "..tostring(World.GetMapId()).." , "..tostring(KBEngineLua.player():GetPosition()).." )    end( "..tostring(World.mapTargetMapId).." , "..Vector3.__tostring(World.mapTargetPos).." )")
	-- 	end
	-- end
	GUILayout.FlexibleSpace()
	GUILayout.EndHorizontal()



	GUILayout.BeginHorizontal()
	entityId = GUIFun.TextField(entityId, "entity id: ", false, space)
	if GUIFun.Button("print", false, 0) then
		if string.len(entityId) <= 0 then
			entityId = tostring(KBEngineLua.player().id)
		end
		local tb = KBEngineLua.entities[tonumber(entityId)]
		local tableMinDepthName = GetTableMinDepthNameMap(tb)
		PrintTable(tb, "entity: "..entityId, nil, tableMinDepthName)
	end
	GUILayout.FlexibleSpace()
	GUILayout.EndHorizontal()

	GUILayout.BeginHorizontal()
	luaStr = GUIFun.TextField(luaStr, "lua table: ", false, space)
	if GUIFun.Button("print", false, 0) and string.len(luaStr) > 0 then
		local tb = loadstring("return "..luaStr)()
		local tableMinDepthName = GetTableMinDepthNameMap(tb)
		PrintTable(tb, "lua table: "..luaStr, nil, tableMinDepthName)
	end
	GUILayout.FlexibleSpace()
	GUILayout.EndHorizontal()



	GUILayout.EndVertical()
	-- 设置开关 end



	GUILayout.EndVertical()
	GUILayout.EndScrollView();

	GUILayout.BeginHorizontal()
	cmdText = GUIFun.TextField(cmdText, "cmd: ", false, space)
	if GUIFun.Button("send", false, 0) then
		self:Cmd(cmdText)
	end
	GUILayout.FlexibleSpace()
	GUILayout.EndHorizontal()




	GUILayout.BeginHorizontal()
	if GUILayout.Button("close", GUIFun.Height(100)) then
		self._funObj:Close()
	end
	GUILayout.EndHorizontal()
	



	GUILayout.EndVertical()
	GUILayout.EndArea()
end

function P:OnGUI()
	GUIFun.Init()
	GUILayout.Box("", GUILayout.Height(Screen.height), GUILayout.Width(Screen.width))
	self:Show()

	local scrollPosition = self.guiInfo.scrollPos
	local scrollDragSpeed = self.guiInfo.scrollDragSpeed

	ImguiWindowCtrl.ScrollByTouch(scrollPosition, scrollDragSpeed)

	-- if UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.Return) then
	-- 	logError("sfdsf")
	-- 	self:Cmd(cmdText)
	-- end
end

-- function P:Update()
	
-- end